package com.smart.community.common.controller;

import com.smart.community.common.base.result.ResponseResult;
import com.smart.community.common.common.vo.SysUserVo;
import com.smart.community.common.service.FileUploadService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.naming.Name;

/**
 * @author 子未语
 */
@RestController
@RequestMapping("/file/upload")
@Api("文件上传")
@Slf4j
public class OssController {
    @Resource
    private FileUploadService fileUploadService;

    @PostMapping("/images")
    @ApiOperation("上传单个文件")
    @ApiImplicitParams({@ApiImplicitParam(name = "file", value = "上传的文件名", required = true, dataType = "__file")})
    @ApiResponses(value = {@ApiResponse(code = 4000, message = "成功", response = String.class),
            @ApiResponse(code = 5000, message = "失败")})
    public ResponseResult<String> uploadImage(@RequestParam("file") MultipartFile file) {
        return ResponseResult.success(fileUploadService.upload(file));
    }

}
